package com.start.ws.handler;

import com.alibaba.fastjson2.JSONObject;
import com.start.ws.Model.StartConnectHeartBeatModel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * 心跳检测组件
 */
@Slf4j
@Component
public class StartWSHeartbeatMsgHandler implements StartBaseSocketMsgHandler<StartConnectHeartBeatModel> {
    @Override
    public String handlerMsgType() {
        return "startHeartbeat";
    }

    /**
     * 接收到消息
     *
     * @param startUserType
     * @param sendClientType  发送人客户类型
     * @param userId          发送人用户id
     * @param msg             消息内容
     * @param sendClientMsgId 发送人客户端消息id
     */
    @Override
    public void onReceive(String startUserType, String sendClientType, String userId, StartConnectHeartBeatModel msg, String sendClientMsgId) {
        log.info(String.format("接收到心跳检测信息:客户端 %s 用户类型：%s 用户id：%s 消息内容：%s", sendClientType, startUserType, userId, JSONObject.toJSONString(msg)));
    }

    @Override
    public StartConnectHeartBeatModel formatMsg(String msg) {
        return JSONObject.parseObject(msg, StartConnectHeartBeatModel.class);
    }
}
